@extends('admin.layouts.master')

@section('content')

<div class="row aw-list">
	<div class="col-md-12 aw-hide">
		<section class="row form-inline aw-list-head">
			<div class="col-sm-4">
				<div class="aw-head-add">
					<button class="btn btn-gules" v-on:click="List_Edit_Layer('add')"><i class="icon-plus"></i> 添加折扣</button>
				</div>
			</div>
		</section>
	</div>
	<div class="col-md-12">
		<section class="panel aw-content">
			<header class="panel-heading">积分及会员等级 - <h5 style="display: inline-block;">提示:如果不启用会员的等级,请将积分范围设置一个比较大的值</h5></header>
			<table class="table table-striped dataTable table-hover">
				<thead>
					<tr>
						<th>ID</th>
						<th>会员等级</th>
						<th>积分范围</th>
						<th>消费折扣</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<tr v-for="(list,key) in lists" :data-key="key" :data-id="list.id">
						<td>@{{list.id}}</td>
						<td>@{{list.level_name}}</td>
						<td>@{{list.start_integral}} - @{{list.end_integral}}</td>
						<td>@{{list.discount}}</td>
						<td>
							<button class="btn btn-green btn-xs" v-on:click="List_Edit_Layer(list.id,key)">
								<i class="icon-pencil"></i> 编辑
							</button>
							<button class="btn btn-gules btn-xs aw-hide" v-on:click="List_Del(list.id,list.level_name)">
								<i class="icon-trash"></i> 删除
							</button>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="aw-text-center aw-list-null" v-if="lists.length==0">暂无数据</div>
			<vue-page :page_item="page_item" :page_this="page_this" :page_all="page_all" :Call_back="Call_back"></vue-page>
			<div class="col-xs-12 aw-hide Js-layer-edit">
				<div class="col-xs-12 aw-p0 aw-mt10 aw-overflow-hidden">
					<h3 class="panel-heading aw-border-none" style="margin-top:0px;">@{{form.level_name}}</h3>
					<div class="col-xs-12 aw-overflow-hidden">
						<label class="control-label col-xs-12 aw-p0 aw-overflow-hidden">积分范围：</label>
						<div class="col-xs-12 aw-p0 form-group aw-overflow-hidden">
							<div class="col-xs-6 aw-pl0">
								<input class="form-control" type="text" placeholder="请输入开始积分" id="start_integral" name="start_integral" v-model="form.start_integral" :value="form.start_integral">
							</div>
							<div class="col-xs-6 aw-pr0">
								<input class="form-control" type="text" placeholder="请输入结束积分" id="end_integral" name="end_integral" v-model="form.end_integral" :value="form.end_integral">
							</div>
						</div>
					</div>
					<div class="col-xs-12 aw-overflow-hidden">
						<div class="col-xs-6 aw-pl0">
							<label class="control-label col-md-12 aw-p0 aw-overflow-hidden">会员等级：</label>
							<div class="">
								<input class="form-control" type="text" placeholder="请输入会员等级" id="level_name" name="level_name" v-model="form.level_name" :value="form.level_name">
							</div>
						</div>
						<div class="col-xs-6 aw-pr0">
							<label class="control-label col-md-12 aw-p0 aw-overflow-hidden">消费折扣：</label>
							<div class="">
								<input class="form-control" type="text" placeholder="请输入消费折扣" id="discount" name="discount" v-model="form.discount" :value="form.discount">
							</div>
						</div>
					</div>
				</div>
				<div class="col-xs-12 aw-overflow-hidden aw-content-btn aw-mt10">
					<a href="javascript:;" class="btn btn-gules Js-layer-edit-btn" v-on:click="List_Save()">保存</a>
					<a href="javascript:;" class="btn btn-gray Js-layer-colse" data-id="add">取消</a>
				</div>
			</div>
		</section>
	</div>
</div>



@section('pagejs')
@parent

<script type="text/javascript" src="/admin/js/vue-page.js"></script>
<script type="text/javascript" src="/admin/js/page.js"></script>
<script type="text/javascript">
var MJS_URLArry=URLArry;
var AD_list={
	api:'/adminapi/userlevel/list',
	form_data:MJS_URLArry,
	tips:false,
}
//默认数据
function VD_form(){
	return data={id:'',level_name:'等级名称',start_integral:'',end_integral:'',discount:''}
}
var Ajax_Vue_Fun=function(vue_data){
	console.log('vue_data')
	console.log(vue_data)
	var Data_Vue=ajax_data_res(vue_data)
	Data_Vue.form={};//添加默认数据
	vm=new Vue({
		el:'#Vue-Body',
		data:Data_Vue,
		components:{
			'vue-page':Vpage
		},methods:{
			Call_back:function(page){
				Vm_Call_back_Page(page)
			},List_Edit_Layer:function(id,key){
				console.warn('Vue-function:添加/编辑项目弹框事件 id='+id);
				var title='添加';
				if(id=='add'){
					$('.Js-layer-edit-btn').html('添加')
					this.form=VD_form()
					Layer_Open()
				}
				if(id>0){
					title='编辑';
					$('.Js-layer-edit-btn').html('保存')
					var edit_info=this.lists[key];
					this.form=edit_info;
					Layer_Open()
				}
				function Layer_Open(){
					layer_index_edit=layer.open({
						type:1,
						title:title+'折扣',
						//closeBtn: 0, //不显示关闭按钮
						area: ['400px','360px'], //宽高
						content:$('.Js-layer-edit'),
						cancel:function(){ 
							MJS_URLArry.id='',
							URL_Make(MJS_URLArry)
						}
					});
				}
			},List_Save:function(){
				var AD_info={
					api:'/adminapi/userlevel/save',
					form_data:this.form,
					tips:'编辑 ['+this.form.level_name+'] 成功',
				}
				var start_integral=parseInt(this.form.start_integral);
				var end_integral=parseInt(this.form.end_integral);
				if(!start_integral){
					msgTips(Placeholder_Text('#start_integral'),2)
					$('#start_integral').focus()
					return;
				}
				if(!end_integral){
					msgTips(Placeholder_Text('#end_integral'),2)
					$('#end_integral').focus()
					return;
				}
				if(start_integral > end_integral){
					msgTips('积分范围开始积分不能大于结束积分',2)
					$('#start_integral').focus()
					return;
				}
				if(this.form.level_name=='等级名称' || !this.form.level_name){
					msgTips(Placeholder_Text('#level_name'),2)
					$('#level_name').focus()
					return;
				}
				if(!this.form.discount){
					msgTips(Placeholder_Text('#discount'),2)
					$('#discount').focus()
					return;
				}
				postData(AD_info,function(){
					URL_Make(MJS_URLArry)
					Vm_List_Get_Data(vm.page_this)
					layer.close(layer_index_edit)
				})
			},List_Del:function(id,name){
				var AD_del={
					api:'/adminapi/userlevel/del',
					form_data:{id:id},
					tips:'删除 ['+name+'] 等级成功',
					msg:'是否删除 ['+name+'] 等级？',
				}
				Vm_List_Status(AD_del)
			}
		}
	})
	console.log('vm')
	console.log(vm)
	if(MJS_URLArry.id=='add'){
		vm.List_Edit_Layer(MJS_URLArry.id)
	}
}
getData(AD_list,Ajax_Vue_Fun)
</script>
@endsection

@endsection

